{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "73bd968b-d970-4a05-94ef-4e7abf990827",
   "metadata": {},
   "source": [
    "Chapter 11\n",
    "\n",
    "# LU分解\n",
    "Book_4《矩阵力量》 | 鸢尾花书：从加减乘除到机器学习 (第二版)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c3656e4-9943-447a-bc6a-83031ca6a96d",
   "metadata": {},
   "source": [
    "这段代码首先定义了一个 $4 \\times 4$ 的矩阵 $ A $，并对其进行 LU 分解，得到三个矩阵：置换矩阵 $P$、下三角矩阵 $L$ 和上三角矩阵 $U$。分解结果满足矩阵关系：\n",
    "\n",
    "$$\n",
    "A = P @ L @ U\n",
    "$$\n",
    "\n",
    "其中：\n",
    "- $P$ 是置换矩阵，用于表示行交换。\n",
    "- $L$ 是具有单位对角线的下三角矩阵。\n",
    "- $U$ 是上三角矩阵。\n",
    "\n",
    "代码利用 `seaborn` 库可视化每个矩阵，展示 LU 分解的过程。通过热图展示，颜色代表矩阵中元素的大小，从而可以更直观地观察分解后矩阵的结构。图形包括 $A$、$P$、$L$、$U$ 的矩阵分解，以“=”和“@”符号连接，最终形成 $A = P @ L @ U$ 的图示分解表达。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6c6f2f2-1bf0-491e-8600-5a833445670e",
   "metadata": {},
   "source": [
    "## 导入库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "03e4473a-a15c-44ef-a4ea-229a35ed0ef2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np  # 导入数值计算库\n",
    "import seaborn as sns  # 导入数据可视化库\n",
    "from scipy.linalg import lu  # 导入 LU 分解函数\n",
    "from matplotlib import pyplot as plt  # 导入绘图库"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73a25e1b-2482-40a5-85ca-9122293767a8",
   "metadata": {},
   "source": [
    "## 定义矩阵 A 并进行 LU 分解"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1b44c738-02af-4db1-85f6-113004c7a5f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "A = np.array([[5, 2, -2, 3],\n",
    "              [-2, 5, -8, 7],\n",
    "              [7, -5, 1, -6],\n",
    "              [-5, 4, -4, 8]])\n",
    "\n",
    "P, L, U = lu(A, permute_l=False)  # 对矩阵 A 进行 LU 分解，得到置换矩阵 P、下三角矩阵 L 和上三角矩阵 U"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8767e062-ada1-49c7-81f9-65a4c228220c",
   "metadata": {},
   "source": [
    "## 可视化矩阵 A、P、L 和 U 的分解过程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "17a1f3cb-456a-4fee-a313-9582886c82c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'U')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA9YAAAEPCAYAAACnR1x8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAkPUlEQVR4nO3deZRU9Zk38Kd6pZVFDdpg3Bh1XA5qIugRlLgkwRe3mDOJJibG0RwnODJ51bjEJPNqcmaUiNEsmMS8EkfenIgZDYxmgiMeGdTBOEB0XDLG4QwGN2QM0iLptfq+f/SCLQh036pbS38+59Sx762ifs9Nqr7cby1NLkmSJAAAAIAhqSn1AAAAAFDJFGsAAABIQbEGAACAFBRrAAAASEGxBgAAgBQUawAAAEhBsQYAAIAUFGsAAABIQbEGAACAFBRrAAAASEGxBoAK09XVFfPnz4/TTz899tprr6irq4vm5uaYPn16zJ8/P/L5fKlHBMqU/IDiyCVJkpR6CABg5zz77LNxzjnnxBtvvBEXXnhhTJ48Ofbdd99oaWmJ3/zmNzF//vzYc88945577ok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kgH1vvfVWdHZ2bvXKQrkZO3Zs1NbWbvVqx/r168t+9qEYN25cRPS88jN+/Pj+/dV6vBSH/OghP3pU6/FSHPKjh/zoUa3HS3HIjx7yo8dQjrco71iPHTs2Dj300O1eRowYsVP3NWXKlHjuuefi9ddf79/30EMPRWNjY0yaNKkY4xdMQ0NDTJo0KZYsWTJg/5IlS2Lq1Kklmqp4JkyYEOPGjRtwvB0dHbFs2bKqPF6KQ370kB/yg8GTHz3kh/xg8ORHD/kx9PwoyjvWg7F27drYsGFDrF27NvL5fDz99NMREXHQQQfFyJEjY/r06XH44YfH+eefH3PmzIkNGzbElVdeGRdffHGMHj26tMPvhCuuuCLOP//8mDx5ckyZMiV+8pOfxNq1a2PmzJmlHm1I3nnnnVi9enX/9po1a+Lpp5+OPfbYI/bbb7+47LLL4oYbboiDDz44Dj744Ljhhhtil112ifPOO6+EU1Ot5EdlkR+UE/lRWeQH5UR+VJbM8iPNrysvhAsuuCCJiK0uS5cu7b/NH/7wh+T0009Pmpqakj322COZNWtW0tbWVrqhB+m2225L9t9//6ShoSE5+uijk2XLlpV6pCFbunTpNv//uuCCC5Ik6fmV9dddd10ybty4pLGxMfnIRz6SPPvss6UdmqolPyqL/KCcyI/KIj8oJ/KjsmSVH7kkSZLBVXEAAACgT9n/c1sAAABQzhRrAAAASEGxBgAAgBQUawAAAEhBsQYAAIAUFGsAAABIQbEGAACAFBRrAAAASEGxBgAAgBQUawAAAEhBsQYAAIAUFGsAAABIQbEGAACAFBRrAAAASEGxBgAAgBQUawAAAEhBsQYAAIAU/j/Y0q8pIl75dgAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 1200x300 with 11 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, axs = plt.subplots(1, 7, figsize=(12, 3))  # 创建子图\n",
    "\n",
    "plt.sca(axs[0])\n",
    "ax = sns.heatmap(A, cmap='RdBu_r', vmax=10, vmin=-10,  # 绘制矩阵 A 的热图\n",
    "                 cbar_kws={\"orientation\": \"horizontal\"})\n",
    "ax.set_aspect(\"equal\")\n",
    "plt.title('A')\n",
    "\n",
    "plt.sca(axs[1])\n",
    "plt.title('=')  # 绘制等号\n",
    "plt.axis('off')\n",
    "\n",
    "plt.sca(axs[2])\n",
    "ax = sns.heatmap(P, cmap='RdBu_r', vmax=10, vmin=-10,  # 绘制置换矩阵 P 的热图\n",
    "                 cbar_kws={\"orientation\": \"horizontal\"})\n",
    "ax.set_aspect(\"equal\")\n",
    "plt.title('P')\n",
    "\n",
    "plt.sca(axs[3])\n",
    "plt.title('@')  # 绘制乘号\n",
    "plt.axis('off')\n",
    "\n",
    "plt.sca(axs[4])\n",
    "ax = sns.heatmap(L, cmap='RdBu_r', vmax=10, vmin=-10,  # 绘制下三角矩阵 L 的热图\n",
    "                 cbar_kws={\"orientation\": \"horizontal\"})\n",
    "ax.set_aspect(\"equal\")\n",
    "plt.title('L')\n",
    "\n",
    "plt.sca(axs[5])\n",
    "plt.title('@')  # 绘制乘号\n",
    "plt.axis('off')\n",
    "\n",
    "plt.sca(axs[6])\n",
    "ax = sns.heatmap(U, cmap='RdBu_r', vmax=10, vmin=-10,  # 绘制上三角矩阵 U 的热图\n",
    "                 cbar_kws={\"orientation\": \"horizontal\"})\n",
    "ax.set_aspect(\"equal\")\n",
    "plt.title('U')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85a80909-2aac-49ed-bb7a-f8cc6b80ee7d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecd322f4-f919-4be2-adc3-69d28ef25e69",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
